package com.mz.ozy.adapter;

import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.SignDayBean;
import com.mz.ozy.utils.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by administrator on 2019/3/29.
 */
public class SignDayAdapter extends BaseQuickAdapter<SignDayBean, BaseViewHolder> {

    private String todayStr;

    public SignDayAdapter(@Nullable List<SignDayBean> data) {
        super(R.layout.item_sign_day, data);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        todayStr = sdf.format(cal.getTime());
    }

    @Override
    protected void convert(BaseViewHolder helper, SignDayBean item) {
        helper.setText(R.id.tv_indicator, StringUtils.changeSN(item.getPrize()));
        if (helper.getAdapterPosition() != 0) {
            helper.setVisible(R.id.line_left, true);
        } else {
            helper.setGone(R.id.line_left, false);
        }

        if (item.getDay().equals(todayStr)) {
            helper.setText(R.id.tv_day, "今天");
            helper.setBackgroundColor(R.id.line_left, ContextCompat.getColor(mContext, R.color.c_ffecb0));
        } else {
            helper.setText(R.id.tv_day, item.getDay().substring(5, 7) + "." + item.getDay().substring(8, 10));
            helper.setBackgroundColor(R.id.line_left, ContextCompat.getColor(mContext, R.color.c_ececec));
        }

        if (item.getState() == 0) {
            helper.setVisible(R.id.tv_indicator, true);
            helper.setGone(R.id.iv_indicator, false);
            helper.setImageResource(R.id.iv_indicator, R.mipmap.indicator_pre);
        } else if (item.getState() == 1) {
            helper.setGone(R.id.tv_indicator, false);
            helper.setVisible(R.id.iv_indicator, true);
            helper.setImageResource(R.id.iv_indicator, R.mipmap.indicator_signed);
        } else {
            helper.setVisible(R.id.tv_indicator, true);
            helper.setGone(R.id.iv_indicator, false);
            helper.setText(R.id.tv_indicator, "补");
            helper.setImageResource(R.id.iv_indicator, R.mipmap.indicator_normal);
        }
        helper.addOnClickListener(R.id.tv_indicator);
    }
}
